<?php

/**
 * 例子
 *
 * @author birdy <freebirdy@foxmail.com>
 * @link http://www.aiyuangong.com
 */

namespace app\seller\controller;

class Demo extends \app\common\controller\Seller
{
    //单文件上传
    function upload()
    {
        if ($this->request->isPost()) {
            //单个上传
            $rs = $this->uploadFile('image', 'image', false);
            dump($rs);
            exit;
        }
        
        return '<h1>单文件上传</h1><form enctype="multipart/form-data" method="post">
                <input type="file" name="image" /> <br> 
                <input type="submit" value="上传" /> 
                </form> ';
    }
    
    
    //覆盖模式
    function replace()
    {
        if ($this->request->isPost()) {
            //单个上传
            $original = 'uploads/images/test.jpg'; //要覆盖的文件
            $rs = $this->uploadFile('image', 'replace', false, ['original'=>$original]);
            dump($rs);
            exit;
        }
        
        return '<h1>覆盖模式上传</h1><form enctype="multipart/form-data" method="post">
                <input type="file" name="image" /> <br> 
                <input type="submit" value="上传" /> 
                </form> ';
    }
    
    //多文件上传
    function upload_muti()
    {
        if ($this->request->isPost()) {
            //单个上传
            $rs = $this->uploadFile('image', 'image', true);
            dump($rs);
            exit;
        }
        
        return '<h1>多文件上传</h1><form enctype="multipart/form-data" method="post">
                <input type="file" name="image[]" /> <br> 
                <input type="file" name="image[]" /> <br> 
                <input type="file" name="image[]" /> <br> 
                <input type="submit" value="上传" /> 
                </form> ';
    }
}
